export const objectToUrlSearch = (data: { [key: string]: any }) => {
  if (!data) return ''

  let search = ''
  Object.keys(data).forEach((k, ind) => {
    if ([undefined, null].includes(data[k])) return

    search += `${ind ? '&' : ''}${k}=${
      typeof data[k] === 'object' ? JSON.stringify(data[k]) : data[k]
    }`
  })
  return search
}

export const appendObjectToUrl = (url: string, data?: { [key: string]: any }) => {
  if (!data) return url

  return `${url}${url.includes('?') ? '&' : '?'}${objectToUrlSearch(data)}`
}
